#ifndef GAME_CPP
#define GAME_CPP
#include"game.h"

bool Game::newWindow(const char* name, int width, int height, int bpp)
{
	//todo: kill previous windows
	if( SDL_Init(SDL_INIT_VIDEO)  != 0 )
	{
		printf( "Unable to initalize SDL: %s\n", SDL_GetError() );
		return 0;
	}
	//SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
	
	SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
	
	screen=SDL_SetVideoMode(width, height, bpp, SDL_OPENGL );
	SDL_WM_SetCaption(name,0);
	
	glViewport(0, 0, screen->w, screen->h);
   glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
   glClearDepth(1.0);
   glDepthFunc(GL_LESS);
   glEnable(GL_DEPTH_TEST);
   glShadeModel(GL_SMOOTH);
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glFrustum(-((GLfloat)screen->w)/64,((GLfloat)screen->w)/64,-((GLfloat)screen->h)/64,((GLfloat)screen->h)/64,1.0f,100.0f); 
	
	
	_cube = new cube(0.0,0.0,-10);
	return 1;
}


bool Game::killWindow()
{
	return true;
}

void Game::display()
{
	static float col=0.0;
	col+=0.1;
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   glMatrixMode( GL_MODELVIEW );
    /*glLoadIdentity( );
     glTranslatef(0.0f,0.0f,-5.0f);
     //glRotatef(0.0f, 0.0f, 0.0f, 1.0f);
     glBegin(GL_TRIANGLES);
     glColor3f(1.0f, cos(col), 0.0f);
     glVertex2f(0.0f, 10.0f);
     glColor3f(cos(col), 1.0f, 0.0f);
     glVertex2f(10.0f, -5.0f);
     glColor3f(0.0f, cos(col), 1.0f);
     glVertex2f(-8.7f, -5.0f);
     glEnd();*/
    
    _cube->draw();
     glFlush();

     SDL_GL_SwapBuffers();
}
#endif
